package common;

import java.util.ArrayList;
import java.util.Random;

import math.common.MathCommon;


public class StatTestTester {
	private int M;
	private StatTest test;
	private StructuralModel modelH0;
	private StructuralModel modelH1;
	
	private Double alpha;
	private Double beta;
	private ArrayList<Double> statH0;
	private ArrayList<Double> statH1;
	
	private Double meanDiff;
	private Double varDiff;
	
	
	public StatTestTester(int m, StatTest test, StructuralModel modelH0,
			StructuralModel modelH1) {
		super();
		M = m;
		this.test = test;
		this.modelH0 = modelH0;
		this.modelH1 = modelH1;
	}

	public void testAlpha_Beta() {
		statH0 = new ArrayList<Double>();
		statH1 = new ArrayList<Double>();
		int falseH0 = 0;
		int falseH1 = 0;
		Random r = new Random();
		r.setSeed(System.currentTimeMillis());
		for (int j=0; j<M; j++) {
		//H0
			test.setV_U(modelH0.getNewData(r));
			Boolean tH0 = test.isH0();
//			statH0.add(test.getStat());
		//H1	
			test.setV_U(modelH1.getNewData(r));
			Boolean tH1 = test.isH0();
//			statH1.add(test.getStat());
			
			if (!tH0)
				falseH0++;
			if (tH1)
				falseH1++;
		}
		alpha =  (double) falseH0/M;
		beta = (double) falseH1/M;
		
		
	}
	
	public void testEstVarH1() {
		ArrayList<Double> estDiff = new ArrayList<Double>();
		for (int j=0; j<M; j++) {
			test.setV_U(modelH0.getNewData());
			estDiff.add(test.getEstDiffH1());
		}
		meanDiff = MathCommon.getMean(estDiff);
		varDiff =  MathCommon.getVar(estDiff);
	}
	
	public Double getAlpha() {
		return alpha;
	}

	public Double getBeta() {
		return beta;
	}

	public void setTest(StatTest test) {
		this.test = test;
	}

	public ArrayList<Double> getStatH0() {
		return statH0;
	}

	public ArrayList<Double> getStatH1() {
		return statH1;
	}

	public Double getMeanDiff() {
		return meanDiff;
	}

	public Double getVarDiff() {
		return varDiff;
	}
	
	
	
	

}
